
package com.xiaomi.mipushdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

import com.xiaomi.mipush.sdk.ErrorCode;
import com.xiaomi.mipush.sdk.MiPushClient;

/**
 * 1，本demo可以直接运行，设置topic和alias。
 * 2，为了修改本demo为使用你自己的appid，你需要修改几个地方：DemoApplication.java中的APP_ID,
 * APP_KEY，AndroidManifest.xml中的package
 * name，和权限permission.MIPUSH_RECEIVE的前缀为你的packagename。
 * 
 * @author wuxiaojun
 */
public class MIPushDemoActivity extends Activity {


    private TextView followTopic;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        followTopic = (TextView) findViewById(R.id.follow_topic);
        final EditText editText = (EditText) findViewById(R.id.input_topic);
        followTopic.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                MiPushClient.subscribe(getApplicationContext(), editText
                        .getText().toString(), null);
                // dumpCall();
            }

            private void dumpCall() {
                MiPushClient.pausePush(getApplicationContext(), null);
                MiPushClient.resumePush(getApplicationContext(), null);
                MiPushClient.setAcceptTime(getApplicationContext(), 0, 0, 0,
                        0, null);
                MiPushClient.setAlias(getApplicationContext(), "alias", null);
                MiPushClient.unsetAlias(getApplicationContext(), "alias", null);
                MiPushClient.subscribe(getApplicationContext(), "topic", null);
                MiPushClient
                        .unsubscribe(getApplicationContext(), "topic", null);
                MiPushClient.unregisterPush(getApplicationContext());
                int err = ErrorCode.ERROR_AUTHERICATION_ERROR;
                err = ErrorCode.ERROR_INTERNAL_ERROR;
                err = ErrorCode.ERROR_INVALID_PAYLOAD;
                err = ErrorCode.ERROR_SERVICE_UNAVAILABLE;
                String v = MiPushClient.COMMAND_SET_ACCEPT_TIME;
                v = MiPushClient.COMMAND_SET_ALIAS;
                v = MiPushClient.COMMAND_UNSET_ALIAS;
            }
        });

        TextView setAlias = (TextView) findViewById(R.id.set_alias);
        setAlias.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                String text = ((EditText) findViewById(R.id.input_alias)).getText().toString();
                MiPushClient.setAlias(getApplicationContext(), text, null);
            }
        });
    }

}
